//
//  CZMainTableViewController.m
//  packDemo
//
//  Created by apple on 16/6/17.
//  Copyright © 2016年 itcast. All rights reserved.
//

#import "CZMainTableViewController.h"
#import <YYModel.h>
#import "CZKindProject.h"
#import "CZCirculPlayPictureViewController.h"
@interface CZMainTableViewController ()<UITableViewDelegate>

/**
 *  展示类型数组
 */
@property (nonatomic,strong) NSArray *projectArr;


@end

@implementation CZMainTableViewController

-(NSArray *)projectArr{
    if (_projectArr == nil) {
        NSString *path = [[NSBundle mainBundle]pathForResource:@"kindsProject.plist" ofType:nil];
        NSArray *arr = [NSArray arrayWithContentsOfFile:path];
        NSMutableArray *nmarray = [NSMutableArray array];
        for (NSDictionary *dict in arr) {
            CZKindProject *model = [CZKindProject yy_modelWithDictionary:dict];
            [nmarray addObject:model];
        }
        _projectArr = nmarray;
    }
    
    return _projectArr;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor redColor];
}


#pragma mark - Table view data source


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.projectArr.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *resuID = @"cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:resuID];
    if (!cell) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:resuID];
    }
    CZKindProject *model = self.projectArr[indexPath.row];
    cell.textLabel.text = model.projectName;

    return cell;
}

//点击跳转对应的demo
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    CZKindProject *model = self.projectArr[indexPath.row];
    //跳转到图片轮播
    if ([model.projectName isEqualToString:@"图片轮播"]) {
        CZCirculPlayPictureViewController *circulVc = [[CZCirculPlayPictureViewController alloc]init];
        circulVc.title = model.projectName;
        [self.navigationController pushViewController:circulVc animated:YES];
    }
}

@end
